<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">提交</button>


    <script>
        let btn =document.getElementById('btn');


        function handle() {
            console.log('像后端1发送请求');
            
        }
        btn.addEventListener('click', debounce(handle,1000));

        //防抖函数1.要有防抖效果，2.不能修改this指向3.不能影响原函数参数
        function debounce(fn,wait) {
            let timer = null;
            return function (...args) {
                if (timer) {
                    clearTimeout(timer);
                }
             timer = setTimeout(() => {
                    fn.call(this,...args) //apply和call的区别：apply是传数组，call是传参数
                },wait);
            }
        }
    </script>
</body>
</html>